package com.origin.chaos.framework.manage.controller;

import com.origin.chaos.common.bean.vo.Result;
import com.origin.chaos.framework.bean.vo.CreateCanvasVo;
import com.origin.chaos.framework.bean.vo.UpdateCanvasVo;
import com.origin.chaos.framework.core.service.ICanvasService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 画布管理模块，供管理员管理画布
 *
 * @author: tao.ding
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/api/canvas-manage")
@Api(tags = "画布管理模块")
@Slf4j
@Validated
public class CanvasManageController {
    private ICanvasService canvasService;

    @ApiOperation("创建一张新的画布")
    @PostMapping("/canvas")
    public Result<Long> addCanvas(@Validated @RequestBody CreateCanvasVo vo) {
        return Result.ofBody(this.canvasService.addCanvas(vo));
    }

    @ApiOperation("修改画布信息")
    @PutMapping("/canvas")
    public Result updateCanvas(@Validated @RequestBody UpdateCanvasVo vo) {
        this.canvasService.updateCanvasEditableInfo(vo);
        return Result.defaultSuccess();
    }

    @Autowired
    @Qualifier("RedisCanvasServiceImpl")
    public void setCanvasService(ICanvasService canvasService) {
        this.canvasService = canvasService;
    }
}
